﻿define(['app'], function(app) {
	'use strict';

	var controller = function controller($scope, Prosaleorder,$stateParams) {

		$scope.act_id = $stateParams.act_id;
		$scope.init_data = function() {
			Prosaleorder.prosaleorder(1, $scope.act_id, function(data) {
				//console.log(data)
				if(data.result) {
					$scope.orders = data.result.orders;
				}

			})
		}
		$scope.init_data();

		//下拉刷新
		$scope.input = new Object();
		$scope.input.nPage = 1;
		$scope.isLoad = false; //可以加载
		//下拉刷新 判断哪个模块进行刷新
		$scope.doRefresh = function() {
			//防止重复加载
			$scope.isLoad = true;
			Prosaleorder.prosaleorder(1, $scope.act_id, function(data) {
					if(data.result.orders != null) {
						$scope.orders = data.result.orders;;
					} else {
						$scope.orders = new Object();
					}
					$scope.input.nPage = 1;
				},
				function() {
					$scope.$broadcast('scroll.refreshComplete');
					$timeout(function() {
						$scope.isLoad = false;
					}, 1500);
				});

		};
		//加载更多
		$scope.doRefreshMore = function() {
			//防止重复加载
			$scope.isLoad = true;
			Prosaleorder.prosaleorder($scope.input.nPage + 1, $scope.act_id, function(data) {
					if(data.result != null) {
						if($scope.orders != undefined) {
							$scope.orders = $scope.orders.concat(data.result.orders);
							$scope.input.nPage += 1;
						} else {
							$scope.orders = data.result.orders;
						}
					}
				},
				function() {
					$scope.$broadcast('scroll.infiniteScrollComplete');
					$timeout(function() {
						$scope.isLoad = false;
					}, 1500);
				});

		};

	}

	controller.$inject = ['$scope', 'Prosaleorder', '$stateParams'];

	return app.registerController("prosaleorderctrl", controller);
});